package com.huifaapp.mall.base.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.huifaapp.mall.base.basemvp.IPresenter;


/**
 * import static android.R.attr.author;
 * import static android.R.attr.description;
 *
 * @author: wangZ
 * @date：2017/6/30 10:54
 * FileName：BaseActivity
 * @description：实现一下IView接口中简单的逻辑几初始化操作 <p>
 * 注意:View层和Presenter层的关联和取笑关联已经在本类里实现,子类无需再实现
 * <p>
 * <p>
 * <p>
 * <p>
 */

public abstract class BaseMvpActivity<P extends IPresenter> extends BaseActivity  {

    private P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = onLoadPresenter();
        //关联View层和Presenter层
        if (mPresenter != null) {
            mPresenter.attachView(this, this);
        }

    }

    @Override
    protected void onDestroy() {
        //解除对Presenter的关联
        if (mPresenter != null) {
            mPresenter.detachView();
        }
        super.onDestroy();
    }

    /**
     * 获取Presenter
     *
     * @return Presenter
     */
    public P getPresenter() {
        return mPresenter;
    }
    /**
     * 加载Presenter
     *
     * @return
     */
    protected abstract P onLoadPresenter();


}